﻿using System;
using System.Configuration;
using System.IO;

namespace Oxage.Common
{
	public class Logger : ILogger
	{
		public static int LogLevel
		{
			get
			{
				return (int)LogLevels.Normal;
			}
		}

		public static void WriteLine(string message)
		{
		}

		#region Static methods
		/// <summary>
		/// Overloaded. Log an exception. Severity level is normal.
		/// </summary>
		/// <param name="ex">Exception.</param>
		public static void Log(Exception ex)
		{
			Log(ex, (int)LogLevels.Normal);
		}

		/// <summary>
		/// Overloaded. Log an exception.
		/// </summary>
		/// <param name="ex">Exception.</param>
		/// <param name="level">Severity level.</param>
		public static void Log(Exception ex, LogLevels level)
		{
			Log(ex, (int)level);
		}

		/// <summary>
		/// Log an exception.
		/// </summary>
		/// <param name="ex">Exception.</param>
		/// <param name="level">Severity level.</param>
		public static void Log(Exception ex, int level)
		{
			//if (ex != null && level <= LogLevel)
			if (ex != null && level == (int)LogLevels.Crash)
			{
				try
				{
					File.WriteAllText("error.log", ex.Message + Environment.NewLine + Environment.NewLine + ex.GetType() + Environment.NewLine + ex.StackTrace);
				}
				catch
				{
				}
			}
		}
		#endregion

		#region ILogger Members
		void ILogger.WriteLine(string message)
		{
			Logger.WriteLine(message);
		}

		void ILogger.Log(Exception ex)
		{
			Logger.Log(ex);
		}
		#endregion
	}

	//Log levels:
	//1..crash, bug needs to be fixed immediately
	//2..basic
	//3..normal (default), bug needs to be fixed sometime
	//4..detail, info for debugging
	//5..very detail, info, all loops
	public enum LogLevels
	{
		Crash = 1,
		Normal = 3,
		Detailed = 5
	}
}
